<template>
	<view class="container">
		<text class="title">完善个人信息</text>
		<view class="">
			<text class="subtitle">提交后不能修改，请仔细确认后再提交!</text>
		</view>
		<form @submit="formSubmit" class="login-form">
			<view class="section">
				<input name="realName" placeholder="姓名" />
			</view>
			<view class="section">
				<input name="phone" placeholder="手机号" />
			</view>
			<view class="section">
				<input name="address" placeholder="住址,如:团结小区2栋101" />
			</view>
			<button class="login-btn" formType="submit" type="primary">确认</button>
		</form>
	</view>
</template>

<script>
	let _self;
	export default {
		data() {
			return {
				f: ''
			};
		},
		onLoad(params) {
			this.f = params.f;
		},
		methods: {
			formSubmit: function(e) {
				let formData = e.detail.value;
				let flag = this.validation(formData);
				if (!flag) {
					return false;
				}
				uni.showLoading({
					title: '处理中...'
				})
				var data = {
					realName: formData.realName,
					phone: formData.phone,
					address: formData.address,
				}
				let that = this;
				this.$sendhttp("/Weixin/fillUserInfo.dhtml", data, function(data) {
					let u = uni.getStorageSync("userinfo");
					u.realName = formData.realName;
					u.phone = formData.phone;
					u.address = formData.address;
					uni.setStorageSync("userinfo", u)
					uni.navigateBack();
				});
			},
			validation: function(_formData) {
				if (_formData.realName.trim() == "") {
					uni.showToast({
						title: '请输入姓名！',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (_formData.phone == "") {
					uni.showToast({
						title: '请输入手机号！',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (_formData.address == "") {
					uni.showToast({
						title: '请输入住址！',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				return true;
			}
		}
	}
</script>

<style lang="less" scoped="scoped">
	.container {
		padding: 30px;
	}

	.section {
		margin: 20px;
		padding: 10px 0px;
		border-bottom: 2upx solid #eee;
	}

	.login-btn {
		margin: 30px 20px 0px 20px;
	}

	.title {
		font-weight: 700;
		font-size: 24px;
		text-align: center;
		display: inline-block;
		width: 100%;
	}

	.subtitle {
		font-size: 14px;
		color: red;
		display: flex;
		justify-content: center;
		margin-top: 10px;
	}
</style>
